import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import "../component" as C
import "qrc:/component/ZGlobal.js" as Global
C.ZModelRect {
    id: rootRangeSettingPage
    radius: 10
    clip: true
    x:596;y:249;width:728;height:582;
    visible:false
    color:"#F3F7FB"
    property alias title: title.text
    property string type: ""

    function setValue(hhText,hText,lText,llText,hhS, hS, lS, llS){
        // console.log("in setvalue >>>>>>>>>>>", hhText)
        hh.text = hhText;
        h.text = hText;
        l.text = lText;
        ll.text = llText;
        hhStatus.checked = (hhS===1);
        hStatus.checked = (hS===1);
        lStatus.checked = (lS===1);
        llStatus.checked = (llS===1);
        errInfo.text=""
    }

    Image {
        x: 40
        y: 40
        source: "qrc:/assets/greenrect.png"
        width: 16
        height: 28
        fillMode: Image.PreserveAspectFit
    }

    Label{
        x:68
        y:36
        Text{
            id: title
            text: "电机设置"
            font.pixelSize: 28
            color: "#333333"
            font.bold: true
        }
    }

    Label{
        x:40
        y:108
        Text{
            text: "报警设置"
            font.pixelSize: 24
            color: "#333333"
        }
    }


    Label{
        x:40
        y:168
        Text{
            text: "高限"
            font.pixelSize: 22
            color: "#333333"
        }
    }

    Label{
        x:382
        y:168
        Text{
            id: deadLine
            text: "高高限"
            font.pixelSize: 22
            color: "#333333"
        }
    }

    C.ZInputImage {
        id: h
        x: 40
        y: 213
        width:243
        source: "qrc:/assets/setting_limit_input.png"
        text: "0.00"
        // 限制只能输入数字和小数点
        validator: RegularExpressionValidator {
            regularExpression: /^[0-9]*\.?[0-9]*$/
        }
    }

    C.ZCheckImage {
        id: hStatus
        x:290;y:216;
    }

    C.ZInputImage {
        id: hh
        x: 382
        y: 213
        width:243
        source: "qrc:/assets/setting_limit_input.png"
        text:""
        // 限制只能输入数字和小数点
        validator: RegularExpressionValidator {
            regularExpression: /^[0-9]*\.?[0-9]*$/
        }
    }

    C.ZCheckImage {
        id: hhStatus
        x:632;y:216;
    }

    Label{
        x:40
        y:312
        Text{
            text: "低限"
            font.pixelSize: 22
            color: "#333333"
        }
    }

    Label{
        x:382
        y:312
        Text{
            text: "低低限"
            font.pixelSize: 22
            color: "#333333"
        }
    }

    C.ZInputImage {
        id: l
        x: 40
        y: 357
        width:243
        source: "qrc:/assets/setting_limit_input.png"
        text: "0.00"
        // 限制只能输入数字和小数点
        validator: RegularExpressionValidator {
            regularExpression: /^[0-9]*\.?[0-9]*$/
        }
    }

    C.ZCheckImage {
        id: lStatus
        x:290;y:360;
    }

    C.ZInputImage {
        id:ll
        x: 382
        y: 357
        width:243
        source: "qrc:/assets/setting_limit_input.png"
        text: "0.00"
        // 限制只能输入数字和小数点
        validator: RegularExpressionValidator {
            regularExpression: /^[0-9]*\.?[0-9]*$/
        }
    }

    C.ZCheckImage {
        id: llStatus
        x:632;y:360;
    }

    Label{
        x:40
        y:420
        Text{
            id: errInfo
            text: ""
            font.pixelSize: 18
            color: "red"
        }

    }
    C.ZButton{
        x: 259
        y: 480
        text: "取消"
        color: "#F3F7FB"
        onClicked: {
            // console.log(">>>>>>>>>>>>")
            //maskRect.destroy();
            //hh.text="10.0"
            rootRangeSettingPage.visible=false;
        }
    }


    C.ZButton{
        x: 492
        y: 480
        text: "确定"
        color: "#178FCD"
        fontColor: "white"
        onClicked: {
            console.log("Range:",hh.text,h.text,l.text,ll.text);

            if (!(parseFloat(hh.text)>parseFloat(h.text) &&
                  parseFloat(h.text)>parseFloat(l.text)&&
                  parseFloat(l.text)>parseFloat(ll.text))){
                errInfo.text="低低限、低限、高限、高高限必有依次增大！"
                return;
            }

            var param = {
                ll:ll.text,
                l:l.text,
                h:h.text,
                hh:hh.text,
                llStatus:llStatus.checked?1:0,
                lStatus:lStatus.checked?1:0,
                hStatus:hStatus.checked?1:0,
                hhStatus:hhStatus.checked?1:0,
            }
            alarmInfo.saveAlarm(param, type);
            rootRangeSettingPage.visible=false;
        }
    }
}

